package com.jin.webvideo.entity;

import java.io.Serializable;
import java.util.List;

public class Page<T> implements Serializable {
    // 总数据量
    private int allCount;
    // 总页数
    private int pageAll;
    // 单页大小
    private int pageSize;
    // 当前页
    private int currentPage;
    // 页数据
    private List<T> list;
    private Page() {

    }

    public static<T> Page<T> createPage(int allCount, int pageSize) {
        return createPage(allCount, pageSize, -1);
    }
    public static<T> Page<T> createPage(int allCount, int pageSize, int currentPage) {
        Page page = new Page();
        page.setCurrentPage(currentPage);
        page.setPageSize(pageSize);
        page.setAllCount(allCount);
        page.setPageAll((int) Math.ceil(allCount* 1.0d / pageSize));
        return page;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getAllCount() {
        return allCount;
    }

    public void setAllCount(int allCount) {
        this.allCount = allCount;
    }

    public int getPageAll() {
        return pageAll;
    }

    public void setPageAll(int pageAll) {
        this.pageAll = pageAll;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public static boolean isValid(Page page) {
        return page.getAllCount() != 0 && page.getCurrentPage() <= page.getPageAll();
    }
}
